<template>
  <div class="page-container">
    <!-- 头部 -->
    <div class="manipulate">
      <div>
        <el-button type="primary" @click="addButton()">添加轮播图</el-button>
        <el-button
          :type="tableHande.dataStaus == 'all' ? 'primary' : ''"
          plain
          @click="tableHande.onClick('all')"
          >全部</el-button
        >
        <el-button
          :type="tableHande.dataStaus == 'unUse' ? 'primary' : ''"
          plain
          @click="tableHande.onClick('unUse')"
          >未使用</el-button
        >
        <el-button
          :type="tableHande.dataStaus == 'use' ? 'primary' : ''"
          plain
          @click="tableHande.onClick('use')"
          >使用中</el-button
        >
      </div>
      <div>
        <el-input
          v-model="tableHande.searchValue"
          style="width: 240px"
          placeholder="请输入图片名称"
        />
        <el-button type="primary" @click="tableHande.onClick()">搜索</el-button>
      </div>
    </div>
    <!-- table -->
    <TableReuse
      :tableData="tableData"
      :columnData="columnData"
      :checkBoxFlag="false"
    >
      <template #controls>
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="scope">
            <el-button
              link
              type="primary"
              size="small"
              @click="handleClick(scope.row)"
              >修改状态</el-button
            >
            <el-button el-button link type="primary" size="small"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </template>
      <template #status>
        <el-table-column prop="status" label="是否可用" width="300">
          <template #default="scope">
            <el-switch
              v-model="scope.row.imageStatus"
              class="mt-2"
              style="margin-left: 24px"
              inline-prompt
              active-value="1"
              inactive-value="0"
              @change="changefun($event, scope.row)"
            />
          </template>
        </el-table-column>
      </template>
    </TableReuse>
    <!-- 分页 -->
    <el-pagination
      background
      layout="total, prev, pager, next"
      @current-change="handleCurrentChange"
      :total="total"
      :current-page="params.pageIndex"
      :page-size="params.pageNumber"
    />
  </div>
</template>
<script setup lang="ts">
/**
 * 模块引入
 */
import { reactive, ref, createApp } from "vue";
import { useRouter, useRoute } from "vue-router";
import Method from "@/api/travel/swiper/Modify";
import TableReuse from "@/components/table/TableReuse";
const router = useRouter();
const route = useRoute();
const table = createApp({});
table.component("TableReuse", TableReuse);
/**
 * 数据
 */
const tableHande = reactive({
  dataStaus: "all",
  filterData: [],
  searchValue: "",
  onClick: (status) => {
    console.log(status);
  },
});
let columnData = [
  {
    key: "_id",
    title: "ID",
    minWidth: 200,
  },
  {
    key: "imageName",
    minWidth: 100,
    title: "图片名称",
  },
  {
    key: "imageType",
    minWidth: 100,
    title: "图片类型",
  },
  {
    key: "imageUrl",
    minWidth: 150,
    type: "img",
    title: "图片预览",
  },
  { key: "imageUrl", title: "图片地址", minWidth: 500 },
  {
    name: "status",
    key: "imageStatus",
    slot: "status",
    title: "图片状态",
    minWidth: 100,
  },
  { key: "creatDate", title: "上传时间", minWidth: 100 },
  {
    name: "controls",
    slot: "controls",
    title: "操作",
    minWidth: 200,
  },
];
let tableData = ref([]);
// let params = ref({ pageIndex: 1, pageNumber: 15, imageName: "" });
/**
 * 功能方法
 */
let total = ref(0);
let params = reactive({
  pageIndex: 1,
  pageNumber: 5,
  imageName: "",
});
// console.log(params.limt);

const handleSizeChange = (val) => {
  console.log(`每页 ${val} 条`);
  params.pageNumber = val;
};
const handleCurrentChange = (val) => {
  console.log(`当前页: ${val}`);
  params.pageIndex = val;
};
const getImg = async () => {
  let res = await Method.getImage(params);
  tableData.value = res.list;
  total.value = res.total;
};
const changefun = (value, arr) => {
  console.log(value, arr);
};
watch(
  params,
  () => {
    console.log("数据发生改变,重新请求数据");
    getImg();
  },
  { immediate: true }
);
</script>
<style lang="less" scoped>
.manipulate {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
</style>
